{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 测试阶段攻击实验"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Using TensorFlow backend.\n"
     ]
    }
   ],
   "source": [
    "import keras\n",
    "from keras.datasets import mnist\n",
    "from keras.models import Sequential\n",
    "from keras.layers import Dense, Dropout, Flatten\n",
    "from keras.layers import Conv2D, MaxPooling2D\n",
    "from keras import backend as K\n",
    "\n",
    "np.set_printoptions(suppress=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 1. 设定参数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "batch_size = 128\n",
    "num_classes = 10\n",
    "epochs = 12\n",
    "img_rows, img_cols = 28, 28"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 2. 处理数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "x_train shape: (60000, 28, 28, 1)\n",
      "60000 train samples\n",
      "10000 test samples\n"
     ]
    }
   ],
   "source": [
    "(x_train, y_train), (x_test, y_test) = mnist.load_data(already_path=\"data/mnist.npz\")\n",
    "\n",
    "if K.image_data_format() == 'channels_first':\n",
    "    x_train = x_train.reshape(x_train.shape[0], 1, img_rows, img_cols)\n",
    "    x_test = x_test.reshape(x_test.shape[0], 1, img_rows, img_cols)\n",
    "    input_shape = (1, img_rows, img_cols)\n",
    "else:\n",
    "    x_train = x_train.reshape(x_train.shape[0], img_rows, img_cols, 1)\n",
    "    x_test = x_test.reshape(x_test.shape[0], img_rows, img_cols, 1)\n",
    "    input_shape = (img_rows, img_cols, 1)\n",
    "\n",
    "x_train = x_train.astype('float32')\n",
    "x_test = x_test.astype('float32')\n",
    "x_train /= 255\n",
    "x_test /= 255\n",
    "print('x_train shape:', x_train.shape)\n",
    "print(x_train.shape[0], 'train samples')\n",
    "print(x_test.shape[0], 'test samples')\n",
    "\n",
    "# convert class vectors to binary class matrices\n",
    "y_train = keras.utils.to_categorical(y_train, num_classes)\n",
    "y_test = keras.utils.to_categorical(y_test, num_classes)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 3. 建立模型"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "WARNING: Logging before flag parsing goes to stderr.\n",
      "W0301 17:18:42.595757  5088 deprecation.py:506] From D:\\dev_tools\\anaconda\\lib\\site-packages\\tensorflow_core\\python\\ops\\resource_variable_ops.py:1630: calling BaseResourceVariable.__init__ (from tensorflow.python.ops.resource_variable_ops) with constraint is deprecated and will be removed in a future version.\n",
      "Instructions for updating:\n",
      "If using Keras pass *_constraint arguments to layers.\n",
      "W0301 17:18:42.623656  5088 module_wrapper.py:139] From D:\\dev_tools\\anaconda\\lib\\site-packages\\keras\\backend\\tensorflow_backend.py:4070: The name tf.nn.max_pool is deprecated. Please use tf.nn.max_pool2d instead.\n",
      "\n",
      "W0301 17:19:07.027828  5088 module_wrapper.py:139] From D:\\dev_tools\\anaconda\\lib\\site-packages\\keras\\backend\\tensorflow_backend.py:422: The name tf.global_variables is deprecated. Please use tf.compat.v1.global_variables instead.\n",
      "\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Train on 60000 samples, validate on 10000 samples\n",
      "Epoch 1/12\n",
      "60000/60000 [==============================] - 26s 428us/step - loss: 0.2648 - accuracy: 0.9187 - val_loss: 0.0595 - val_accuracy: 0.9810\n",
      "Epoch 2/12\n",
      "60000/60000 [==============================] - 14s 232us/step - loss: 0.0921 - accuracy: 0.9733 - val_loss: 0.0381 - val_accuracy: 0.9877\n",
      "Epoch 3/12\n",
      "60000/60000 [==============================] - 13s 224us/step - loss: 0.0680 - accuracy: 0.9795 - val_loss: 0.0361 - val_accuracy: 0.9867\n",
      "Epoch 4/12\n",
      "60000/60000 [==============================] - 13s 224us/step - loss: 0.0562 - accuracy: 0.9832 - val_loss: 0.0331 - val_accuracy: 0.9893\n",
      "Epoch 5/12\n",
      "60000/60000 [==============================] - 13s 224us/step - loss: 0.0472 - accuracy: 0.9858 - val_loss: 0.0291 - val_accuracy: 0.9905\n",
      "Epoch 6/12\n",
      "60000/60000 [==============================] - 14s 228us/step - loss: 0.0433 - accuracy: 0.9870 - val_loss: 0.0315 - val_accuracy: 0.9893\n",
      "Epoch 7/12\n",
      "60000/60000 [==============================] - 13s 225us/step - loss: 0.0394 - accuracy: 0.9880 - val_loss: 0.0269 - val_accuracy: 0.9904\n",
      "Epoch 8/12\n",
      "60000/60000 [==============================] - 13s 224us/step - loss: 0.0359 - accuracy: 0.9890 - val_loss: 0.0281 - val_accuracy: 0.9911\n",
      "Epoch 9/12\n",
      "60000/60000 [==============================] - 13s 225us/step - loss: 0.0342 - accuracy: 0.9895 - val_loss: 0.0248 - val_accuracy: 0.9919\n",
      "Epoch 10/12\n",
      "60000/60000 [==============================] - 14s 234us/step - loss: 0.0298 - accuracy: 0.9910 - val_loss: 0.0271 - val_accuracy: 0.9911\n",
      "Epoch 11/12\n",
      "60000/60000 [==============================] - 14s 230us/step - loss: 0.0302 - accuracy: 0.9908 - val_loss: 0.0257 - val_accuracy: 0.9916\n",
      "Epoch 12/12\n",
      "60000/60000 [==============================] - 14s 230us/step - loss: 0.0277 - accuracy: 0.9915 - val_loss: 0.0258 - val_accuracy: 0.9925\n",
      "Test loss: 0.025783601510136395\n",
      "Test accuracy: 0.9925000071525574\n"
     ]
    }
   ],
   "source": [
    "model = Sequential()\n",
    "model.add(Conv2D(32, kernel_size=(3, 3),\n",
    "                 activation='relu',\n",
    "                 input_shape=input_shape))\n",
    "model.add(Conv2D(64, (3, 3), activation='relu'))\n",
    "model.add(MaxPooling2D(pool_size=(2, 2)))\n",
    "model.add(Dropout(0.25))\n",
    "model.add(Flatten())\n",
    "model.add(Dense(128, activation='relu'))\n",
    "model.add(Dropout(0.5))\n",
    "model.add(Dense(num_classes, activation='softmax'))\n",
    "\n",
    "model.compile(loss=keras.losses.categorical_crossentropy,\n",
    "              optimizer=keras.optimizers.Adadelta(),\n",
    "              metrics=['accuracy'])\n",
    "\n",
    "model.fit(x_train, y_train,\n",
    "          batch_size=batch_size,\n",
    "          epochs=epochs,\n",
    "          verbose=1,\n",
    "          validation_data=(x_test, y_test))\n",
    "score = model.evaluate(x_test, y_test, verbose=0)\n",
    "print('Test loss:', score[0])\n",
    "print('Test accuracy:', score[1])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 4. 开始攻击"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 165,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "from matplotlib import pyplot as plt"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 4.1 找到高威胁测试样本"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 169,
   "metadata": {},
   "outputs": [],
   "source": [
    "atk_score_dict = {}\n",
    "for test_index in range(x_test.shape[0]):\n",
    "    sig_score = model.evaluate(np.array([x_test[test_index]]), np.array([y_test[test_index]]), verbose=0)[0]\n",
    "    atk_score_dict[sig_score] = test_index\n",
    "\n",
    "att_scores = np.array(list(atk_score_dict.keys()))\n",
    "sorted_scores = np.sort(att_scores)[-10:]\n",
    "att_test_index= [atk_score_dict[i] for i in sorted_scores]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 4.2 观看高威胁样本"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 181,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAU4AAAD7CAYAAAAFI30bAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAAC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naqy6EEEnRsPk4w4sA3tPzk77e82wLn7cxHPAc3opXDYsXL07kfUR8/EYH/1gpU6dODY4T8DRFBMKZxk488USgkFf1888/B+DRRx8N2niv0m+bbSuL/+zZs4HCaMVnvwLo3bt3YraXQh6nEELEpGE9zmHDhgXHt956K1De0/Rce+21QHEA9SOPPALA7bffXvQIsGTJEgC+/PLLKi0WlXLfffcBcMghh9T8XuG6RKI2+NHe4YcfXvQIxWsXUPhuh9ctouDnSsPJfDzhrbe1Qh6nEELERB2nEELEpGHDkaZNmxZ+HVDIeBMFv6sEYM899wQKBby+853vBNf8biRfBGrevHmR71EBCltpg169egHwz3/+MzjnS14sjy+sBoV9yv715fIF/OEPfwCKi70lWDpYuobwma0OO+ywkm18LolBgwYBsHTp0lj3OP300wE444wzgOLywH6HXwK7+RSOJIQQSdGwHufAgQOD4+effx6Aq6++GoAzzzwzuPbOO9FzFfhA6XCeP78g4ReTDjjgAKDgzSSMPJMyhEsyr7TSSkBhlOAD1/3iHxQW9Hyg9CabbNLqPf0ed59TIGpm/5hI1xD+e+q1u/zyy4Nr22+/PVDIYuazGkXNuO+/nz7w3f/NhAsw+hwECSCPUwghkqJhPc4wPpzh3HPPBYq3Z/lwBu+JPPbYYxXZ5ufAfFjEt771reBagl6KPJMEGTEityXb52IN4+e3jj76aACuvPLKWpoiXUN4j/Pggw8GikOG/Nymr/vlR4zhLZP++1auPLDfjFKvEaI8TiGEiEmUKpd9gGuAtYEvgXHOuYvSrJrns3n7x+OPPz64tvPOOwPw97//HShUu3zggQcivXePHj2AwpYt75nUaC6sYWgEXavltNNOK3nNb5aosafZcDSCruussw5QGBmGR29+Ptp/X/21rbbaKmjjPc1f//rXQHGuTR/14r3YZ599NvlfIAJRPM5lwPHOuQHAYOBIMxuIquZlHenanEjXFGi343TOLXDOPZs/XgLMBHqRq5rnJx8mA633PomGRbo2J9I1HWLtVc+XHB0EPEWMiohJc/7557c67t69O1DI6RjOluL57ne/C7RdIsEPIfykdUeiUXSNQrio14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vDfwdkr3jo2ZdSYnwnXOudvzpxfm51P8vMo79bKvwciMttI1FtK1DGl1nNOA/mbWz8xWAoYDU1K6dyzMzIDxwEzn3AWhS1OAUfnjUcAdadvWoGRCW+kaG+la7r5pBcCb2R7An4BOwATn3Lmp3DgmZrYd8CjwEvBl/vQYcvMmNwPrAHOBYc65RXUxssHIgrbSNT7Stcx9tXNICCHioZ1DQggRE3WcQggRE3WcQggRE3WcQggRE3WcQggRE3WcQggRE3WcQggRE3WcQggRk/8HcqZKHyT7d2UAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 9 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "danger_test = [x_test[i] for i in att_test_index]\n",
    "for num in range(9):\n",
    "    plt.subplot(3,3,num+1)\n",
    "    plt.imshow(danger_test[num].squeeze(), cmap='gray')\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 4.3 使用特征矩阵 | 特征值的攻击"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 188,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(28, 28)"
      ]
     },
     "execution_count": 188,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "danger_9 = x_test[att_test_index[0]].squeeze()\n",
    "danger_9.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 189,
   "metadata": {},
   "outputs": [],
   "source": [
    "eig, fea = np.linalg.eig(danger_9)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 192,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(28, 28)"
      ]
     },
     "execution_count": 192,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "fea.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 226,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "D:\\dev_tools\\anaconda\\lib\\site-packages\\ipykernel_launcher.py:1: ComplexWarning: Casting complex values to real discards the imaginary part\n",
      "  \"\"\"Entry point for launching an IPython kernel.\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "<matplotlib.image.AxesImage at 0xcb30e948>"
      ]
     },
     "execution_count": 226,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAPsAAAD4CAYAAAAq5pAIAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8QZhcZAAAOWklEQVR4nO3dX4wV93nG8efhn80avOBSG+xFThz5onblOvUaWXJUUUWNiC+Mc5EqCCEqWSUXsUSkCNVyL2L5yipNolxUsUiNQlDqKFJimQurDSBkN5IVeW1RG0prXIuGDWsgmL9eA7vw9mKHasG7M8vM+Wfe70danXPmd2bm1YFn5+x5z8zPESEAN75Z3S4AQGcQdiAJwg4kQdiBJAg7kMScTu5s/vz50d/f38ldIrGBgYFpx4aHhztYSeecPn1an3zyiacaaxR226sk/VDSbEn/HBHPlz2/v79f69ata7JLYMY2b9487dimTZs6WEnnbN++fdqx2m/jbc+W9E+SvirpPklrbN9Xd3sA2qvJ3+wrJL0fER9ExEVJP5e0ujVlAWi1JmG/S9LhSY+Hi2VXsb3B9pDtodHR0Qa7A9BEk7BP9SHAp757GxFbImIwIgb7+voa7A5AE03CPixp+aTHA5KONCsHQLs0Cfubku61/Xnb8yR9Q9KO1pQFoNVqt94iYtz2U5L+TROtt60Rsb9llQENlbXXytpyVet+VjXqs0fEq5JebVEtANqIr8sCSRB2IAnCDiRB2IEkCDuQBGEHkujo+exAr6jqo9+IfXiO7EAShB1IgrADSRB2IAnCDiRB2IEkaL0BU7gRW3Mc2YEkCDuQBGEHkiDsQBKEHUiCsANJEHYgCfrsQA2f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QdSIKwA0kQdiCJyvPZW7oz+7ik/520aImkP3SsgOvTq7X1al0StdXVytrujog/nmqgo2H/1M7toYgY7FoBJXq1tl6tS6K2ujpVG2/jgSQIO5BEt8O+pcv7L9OrtfVqXRK11dWR2rr6NzuAzun2kR1AhxB2IImuhN32Ktv/bft92093o4bp2D5k+13be20PdbmWrbaP2d43adlttnfaPljcTjnHXpdqe9b274vXbq/tx7pU23Lbe2wfsL3f9sZieVdfu5K6OvK6dfxvdtuzJb0n6a8kDUt6U9KaiPjPjhYyDduHJA1GRNe/gGH7LySdk/TTiPjTYtk/SPooIp4vflEujoi/65HanpV0rtvTeBezFS2bPM24pCck/Y26+NqV1PXX6sDr1o0j+wpJ70fEBxFxUdLPJa3uQh09LyJel/TRNYtXS9pW3N+mif8sHTdNbT0hIkYi4u3i/llJV6YZ7+prV1JXR3Qj7HdJOjzp8bB6a773kPRr22/Z3tDtYqZwx5Vptorb27tcz7Uqp/HupGumGe+Z167O9OdNdSPsU00l1Uv9v0cj4s8lfVXSt4q3q5iZGU3j3SlTTDPeE+pOf95UN8I+LGn5pMcDko50oY4pRcSR4vaYpJfVe1NRH70yg25xe6zL9fy/XprGe6ppxtUDr103pz/vRtjflHSv7c/bnifpG5J2dKGOT7F9S/HBiWzfIukr6r2pqHdIWl/cXy/plS7WcpVemcZ7umnG1eXXruvTn0dEx38kPaaJT+T/R9Lfd6OGaeq6R9J/FD/7u12bpJc08bZuTBPviJ6U9EeSdks6WNze1kO1bdfE1N7vaCJYy7pU25c08afhO5L2Fj+Pdfu1K6mrI68bX5cFkuAbdEAShB1IgrADSRB2IAnCDiRB2IEkCDuQxP8B9pCI89OzrKkAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.imshow(fea.astype(np.float32),cmap='gray')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 250,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "原图 A 的 Loss:8.4638240878121e-06 | 攻击图 A 的 Loss:0.00029392691794782877\n",
      "原图 B 的 Loss:1.311301275563892e-06 | 攻击图 B 的 Loss:0.01260386686772108\n",
      "A 图攻击成功\n",
      "B 图攻击成功\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "D:\\dev_tools\\anaconda\\lib\\site-packages\\ipykernel_launcher.py:8: ComplexWarning: Casting complex values to real discards the imaginary part\n",
      "  \n",
      "D:\\dev_tools\\anaconda\\lib\\site-packages\\ipykernel_launcher.py:9: ComplexWarning: Casting complex values to real discards the imaginary part\n",
      "  if __name__ == '__main__':\n"
     ]
    }
   ],
   "source": [
    "ori_a = np.array([x_test[7]])\n",
    "ori_b = np.array([x_test[9]])\n",
    "l_a = np.array([y_test[7]])\n",
    "l_b = np.array([y_test[9]])\n",
    "\n",
    "att_a = ori_a + np.array([np.expand_dims(fea,2)])*0.5\n",
    "att_b = ori_b + np.array([np.expand_dims(fea,2)])\n",
    "att_a = att_a.astype(np.float32)\n",
    "att_b = att_b.astype(np.float32)\n",
    "\n",
    "r_ori_a = model.evaluate(ori_a, l_a, verbose=0)[0]\n",
    "r_ori_b = model.evaluate(ori_b, l_b, verbose=0)[0]\n",
    "\n",
    "r_att_a = model.evaluate(att_a, l_a, verbose=0)[0]\n",
    "r_att_b = model.evaluate(att_b, l_b, verbose=0)[0]\n",
    "\n",
    "print(\"原图 A 的 Loss:{} | 攻击图 A 的 Loss:{}\".format(r_ori_a, r_att_a))\n",
    "print(\"原图 B 的 Loss:{} | 攻击图 B 的 Loss:{}\".format(r_ori_b, r_att_b))\n",
    "\n",
    "if r_ori_a < r_att_a:\n",
    "    print(\"A 图攻击成功\")\n",
    "if r_ori_b < r_att_b:\n",
    "    print(\"B 图攻击成功\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 4.4 攻击方案1 图像可视化"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 251,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAATsAAAD7CAYAAAAVQzPHAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8QZhcZAAAcWUlEQVR4nO3de4yVxfkH8O8jwq5cZYFFkJuXrbK1ChQv0RKkSkGsUq0W0BjS0FINpNjaKsWmaWsvJkRr2p+1YsRFa6Gk0kKVtLFbyQopCBgEAWEXuQiuLBeVu7Awvz/2MMyMvO+ePec97/vume8n2Zxnzpxz3gk7O7wzZy6ilAIRUbE7J+kCEBHFgY0dEXmBjR0ReYGNHRF5gY0dEXmBjR0ReSGvxk5ERovIJhGpE5HpURWKKGms28VHcp1nJyJtAGwGMBLATgArAUxQSm2IrnhE8WPdLk7n5vHeawDUKaXeBwARmQdgLIDACiEinMGcHnuVUj2SLkRKtahut23bVpWWlsZYvNajS5cuOv70008Lfr1Dhw4F1ut8GrsLAXxgpHcCuDaPz6N4bU+6ACnWorpdWlqKIUOGFLxQrdGtt96q49dee63g16upqQms1/k0dnKW5z535yYikwFMzuM6RHFrtm6b9bqkpCSOMlGe8vmCYieAvka6D4AP3RcppWYppYYqpYbmcS2iODVbt8163bZt21gLR7nJ585uJYAKEbkIwC4A4wHcE0mpiJLFuh0Rs+tqdmndvDjk3NgppRpFZCqAfwNoA2C2Ump9ZCUjSgjrdnHK584OSqnFABZHVBai1GDdLj55NXZERNlyu61xf1PL5WJE5AU2dkTkBTZ2ROQFjtkRUSLinpbCOzsi8gIbOyLyAruxRJS4OKal8M6OiLzAxo6IvMDGjoi8wDE7IkqdQkxL4Z0dEXmBjR0ReYHd2IzOnTvr+Le//a2Vd8UVV+j45ptvtvJOnDhR2IJR0cq1e1ZXV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Jqjz8yfv3mVjdZr3O7ocrKIjIC1xBQUReYGNHRF5gY0dEXmBjR0ReYGNHRF5gY0dEXmBjR0ReYGNHRF74fxRzM53j0qrDAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 4 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.subplot(2,2,1)\n",
    "plt.imshow(ori_a.squeeze(), cmap='gray')\n",
    "plt.subplot(2,2,2)\n",
    "plt.imshow(att_a.squeeze(), cmap='gray')\n",
    "plt.subplot(2,2,3)\n",
    "plt.imshow(ori_b.squeeze(), cmap='gray')\n",
    "plt.subplot(2,2,4)\n",
    "plt.imshow(att_b.squeeze(), cmap='gray')\n",
    "\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 4.5 使用均值与标准差形成一般分布进行攻击"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 215,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "均值：0.09338735789060593， 标准差：0.2637976109981537\n"
     ]
    }
   ],
   "source": [
    "mean = danger_9.mean()\n",
    "std = danger_9.std()\n",
    "print(\"均值：{}， 标准差：{}\".format(mean,std))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 237,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "原图 A 的 Loss:8.4638240878121e-06 | 攻击图 A 的 Loss:0.04645919054746628\n",
      "原图 B 的 Loss:1.311301275563892e-06 | 攻击图 B 的 Loss:0.0006930810050107539\n",
      "A 图攻击成功\n",
      "B 图攻击成功\n"
     ]
    }
   ],
   "source": [
    "var = np.array(np.random.normal(loc=mean, scale=std, size=(28,28,1)))\n",
    "\n",
    "ori_a = np.array([x_test[7]])\n",
    "ori_b = np.array([x_test[9]])\n",
    "l_a = np.array([y_test[7]])\n",
    "l_b = np.array([y_test[9]])\n",
    "\n",
    "att2_a = ori_a + var\n",
    "att2_b = ori_b + var\n",
    "att2_a = att2_a.astype(np.float32)\n",
    "att2_b = att2_b.astype(np.float32)\n",
    "\n",
    "r_ori_a = model.evaluate(ori_a, l_a, verbose=0)[0]\n",
    "r_ori_b = model.evaluate(ori_b, l_b, verbose=0)[0]\n",
    "\n",
    "r_att2_a = model.evaluate(att2_a, l_a, verbose=0)[0]\n",
    "r_att2_b = model.evaluate(att2_b, l_b, verbose=0)[0]\n",
    "\n",
    "print(\"原图 A 的 Loss:{} | 攻击图 A 的 Loss:{}\".format(r_ori_a, r_att2_a))\n",
    "print(\"原图 B 的 Loss:{} | 攻击图 B 的 Loss:{}\".format(r_ori_b, r_att2_b))\n",
    "\n",
    "if r_ori_a < r_att_a:\n",
    "    print(\"A 图攻击成功\")\n",
    "if r_ori_b < r_att_b:\n",
    "    print(\"B 图攻击成功\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 4.6 攻击方案1 图像可视化"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 233,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAATsAAAD7CAYAAAAVQzPHAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8QZhcZAAAgAElEQVR4nO2deZRU1fHHv8XIvsiiIAICCqKICyIiEldE0SjiFgWScBIjaiRRYxI5/pKcnGBiEoyaxRPFiBDlEFFRIWpEWURRlEVANtmUTWRxQUTBQe7vj2kuVeV0zzDTdPfM+37OmTN1u16/d7u5c3lVrxYJIYAQQqo7NfI9AUIIyQXc7AghiYCbHSEkEXCzI4QkAm52hJBEwM2OEJIIKrXZiUhfEXlXRFaKyLBsTYqQfMO1Xf2QisbZiUgRgOUA+gBYD2A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YnVZtdu3YZc01X5dCNagCgRo199xc+S0Kbct5U1KEhPhdXX2/RokVG17lz5yh701hn//iim/379zfjefPmRblXr15Gp4tp+hAWXdjz2GOPNTr9N+DNaF31xId36bHvd5sJ3tkRQhIBNztCSCLgZkcISQTlqlSctYvluFKxb6qjG5V4v4dOc8n0nejqqgBw0003mbH2X/hGIQ899FCUb7jhhrTXyBGsVJwl6tevH7TPV/vGfEVs3UjHr0FdBcT7hnVKlq6qDQA//OEPo+xTsnTDG1/1RFc68U2yfchMq1atouwrq+iKJb4a98yZM6Psw7a0zvvldGqbD9nSn+ONN94wuk2bNmW9UjEhhFQpuNkRQhIBNztCSCKo1j47j+4S9uSTTxqd9p/470Q3u7799tuNzpeD+sMf/hDlYcNsF741a9aUOhfgm3FVOYA+uyzRsGHDoKti60q+fn3ouDtfzl3H4PkOdzqe01fg1mlnV155pdFpf5ePCdUpWWPGjDE6X5pKx+T5+EBdVmry5MlGp/1yvhyTLhWlqw8DwGOPPRZlHecKANOmTYuyrv4NAPfeey99doSQZMPNjhCSCKp1uphHh4342/2BAwdG2d/u/+Y3v4myN0s8w4cPj7JPj9HpavqcADB48OCM5yWFjTZB69atG2XfyEabsb7Shw638KaqDllZvXq10enzzJgxw+h06Mnpp59udE899VSUfeiHvh5g08W0OwYArr766ijrisqA/V501WLAuot8ZZMTTjghyr4Blv5O98f9wzs7Qkgi4GZHCEkE3OwIIYkgUT47jU/78uOKov0uukosYH1255xzjtHp1DY20K5aiAiKioriWHfK8h3ldKrV4YcfbnS6HJJObQRs6McVV1xhdHrten+zTt/yPrPi4uJSzw98s+ST9r35NEwdJuN92vXr14+y/o4AW8VYnx+wnQF9V7QTTzwxyjp8pix4Z0cISQTc7AghiSCxZmwuGD9+vBlrM1Y/rgeAoUOHRvl3v/vdgZ0YySq1atUylTh0uIev3KvDRrQZ5/Emn65m4k1jbXJqUxiwlVRat25tdF9//XWUdVaCfx9gQ7V0U27Aul1uvPFGo9OhNj5kRpu4vpKKDmHxFVn09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auNhsBa/INGjTI6CZNmhTls88+2+h0YU/Amti+0KcOi/Hz1uEubdq0MbqBAwdG2TcD0lWJdPFcwGZ3+KonI0aMoBlLCEk23OwIIYmAmx0hJBHk2me3BcAaAIcA2FrG4bkiqXNpG0I4tOzDSFkU6LoGCms+uZpL2nWd080uXlRkTqE4xzkXki0K7d+vkOZTCHOhGUsISQTc7AghiSBfm93IPF23NDgXki0K7d+vkOaT97nkxWdHCCG5hmYsISQR5HSzE5G+IvKuiKwUkWG5vHbq+qNEZLOILFKvNRWRl0RkRep3k0znyOJc2ojINBFZKiKLReTmfM6HVI58rm2u6/KRs81ORIoA3A/gQgCdAQwQkc6Z35V1RgPo614bBmBKCKEjgCmpcS7YDeC2EMKxAE4DcFPq+8jXfEgFKYC1PRpc12WSyzu7UwGsDCGsDiF8BeA/AC7N4fURQpgB4GP38qUAxqTkMQD652guG0MI81LydgBLAbTK13xIpcjr2ua6Lh+53OxaAdDVA9enXss3LUIIG4GSfygAzcs4PuuISDsAXQG8WQjzIftNIa7tvK+jQlvXudzspJTXEv8oWEQaAHgKwC0hhM/yPR9SIbi2HYW4rnO52a0HoAtatQbwQQ6vn45NItISAFK/N5dxfNYQkZooWRBjQwgT8j0fUmEKcW1zXTtyudnNBtBRRNqLSC0A1wCYmMPrp2MigMEpeTCAZ3NxUSlpxPkwgKUhBN0QIy/zIZWiENc217UnhJCzHwAXAVgOYBWA/8vltVPXHwdgI4BilPxvfC2AZih5OrQi9btpjubyLZSYOgsBzE/9XJSv+fCn0v+eeVvbXNfl+2EGBSEkETCDghCSCLjZEUISATc7Qkgi4GZHCEkE3OwIIYmAmx0hJBFwsyOEJAJudoSQRPD/Q5L8kcX8N3kAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 4 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.subplot(2,2,1)\n",
    "plt.imshow(ori_a.squeeze(), cmap='gray')\n",
    "plt.subplot(2,2,2)\n",
    "plt.imshow(att2_a.squeeze(), cmap='gray')\n",
    "plt.subplot(2,2,3)\n",
    "plt.imshow(ori_b.squeeze(), cmap='gray')\n",
    "plt.subplot(2,2,4)\n",
    "plt.imshow(att2_b.squeeze(), cmap='gray')\n",
    "\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
